import cjs=createjs;
/**
 * 初始化舞台
 * @param {*} canvas 
 * @param {Number} FPS 
 * @returns {cjs.Stage}
 */
const stageInit=(canvas:HTMLCanvasElement,FPS=60,enableMouseOver=false,update?:any):cjs.Stage=>{
    const stage = new cjs.Stage(canvas);
    if(enableMouseOver)stage.enableMouseOver();
            cjs.Ticker.framerate=FPS;
            cjs.Ticker.addEventListener("tick", ()=> {
                stage.update();
                update&&update();
            });
    return stage
}
/**
 * 
 * @param assets 加载资源列表
 * @param fileload 单个资源成功下载
 * @param plugin 资源类型
 * @returns 
 */
const loadManifestAsync=(assets:any[],fileload?:()=>void,plugin?:()=>void):Promise<cjs.LoadQueue>=>{
    return new Promise((resolve, reject)=>{
        const loader = new cjs.LoadQueue(false);
    loader.addEventListener("complete", ()=>{resolve(loader)});
    if(fileload)
    loader.addEventListener('fileload', fileload);
    loader.addEventListener('error',()=>{reject()})
    if(plugin)
    loader.installPlugin(plugin);
    loader.loadManifest(assets)
    })
}

export {stageInit,loadManifestAsync}